package com.example.dc.Controller;


import com.example.dc.utils.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/session")
public class SessionControll {
    @GetMapping("/setsession")
    public Result setSession(HttpSession session){
        //设置session
        session.setAttribute("name","pencil");
        return Result.success();
    }

    @GetMapping("/getsession")
    public Result getSession(HttpServletRequest request){
        HttpSession session=request.getSession();
        Object name=session.getAttribute("name");
        return Result.success(name);
    }

}
